#include<bits/stdc++.h>
using namespace std;
const int MAXN =1000006;
//const int MAXN =10004;

int colorOne(int n, int* ai){
	int a[MAXN] = {0};
	for(int i = 0; i<n; i++) a[ai[i]]++;
	int cnt =0;
	for(int i = MAXN - 1; i>=0; i--){
		if(a[i] >= 2) cnt += (a[i]-1)*i;
	}
	return cnt;
}

int main(){
	freopen("color.in", "r", stdin);
	freopen("color.out", "w", stdout);
	int t = 0;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		int a[n];
		for(auto& i:a) cin >> i;
		cout << colorOne(n, a) << endl;
	}
	return 0;
}
